<include file="Common/header" />
<title>会员录入</title>
<script type="text/javascript" src="__PUBLIC__/h-ui/lib/jquery/1.9.1/jquery.form.js"></script>
<style type="text/css">
	#imgshow img {width: 100px; height: 100px; margin-right: 10px;}
</style>
</head>
<body>
<div class="pd-10">
	<div class="panel panel-primary">
		<div class="panel-header">用户基本信息</div> 
		<table class="table table-border table-bordered table-striped">
            <tr>
				<td style="background-color: #f9f9f9;text-align: right">联系方式：</td>
                <td style="background-color: white">
					<input type="text" name="phone" id="phone" class="input-text radius" value="{$userinfo['phone']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">客人姓名：</td>
                <td style="background-color: white">
					<input type="hidden" name="userid" id="userid" value="{$userinfo['userid']}" />
					<input type="text" name="nickname" id="nickname" class="input-text radius" value="{$userinfo['nickname']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">身份证：</td>
                <td style="background-color: white;">
					<input type="text" name="card" id="card" class="input-text radius" value="{$userinfo['card']}" />
                </td>
            </tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">紧急联系人：</td>
                <td style="background-color: white">
					<input type="text" name="emergency_name" id="emergency_name" class="input-text radius" value="{$userinfo['emergency_name']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">紧急联系方式：</td>
                <td style="background-color: white">
					<input type="text" name="emergency_phone" id="emergency_phone" class="input-text radius" value="{$userinfo['emergency_phone']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">联系地址：</td>
                <td style="background-color: white">
					<input type="text" name="address" id="address" class="input-text radius" value="{$userinfo['address']}" />
				</td>
			</tr>
		</table>
	</div>
	<div class="panel panel-success">
		<div class="panel-header">合同基本信息</div> 
		<table class="table table-border table-bordered table-striped">
            <tr>
                <td style="background-color: #f9f9f9;text-align: right">合同编号：</td>
                <td style="background-color: white;">
					<input type="text" class="input-text radius" name="contract" id="contract" value="{$userinfo['contract']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">租房类型：</td>
				<td style="background-color: white">
					<span class="select-box radius">
						<select class="select radius" id="type" name="type">
							<option value="长租" <?php echo $userinfo['is_review'] == 1 ? 'selected' : '';?>>长租</option>
							<option value="短租" <?php echo $userinfo['is_review'] == 0 ? 'selected' : '';?>>短租</option>
						</select>
					</span>
				</td>
				<td style="background-color: #f9f9f9;text-align: right"></td>
				<td style="background-color: white"></td>
            </tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">所属分店：</td>
                <td style="background-color: white">
					<span class="select-box radius">
						<select class="select" size="1" name="shop_id" id="shop_id">
							<option value="0">--请选择分店--</option>
							<?php foreach($shoplist as $spl){ ?>
							<option value="{$spl['shop_id']}" {$userinfo['shop_id'] == $spl['shop_id'] ? 'selected' : ''}>{$spl['title']}</option>
							<?php } ?>
						</select>
					</span>
				</td>
				<td style="background-color: #f9f9f9;text-align: right">所属小区：</td>
                <td style="background-color: white;">
					<span class="select-box radius">
						<select class="select" size="1" name="villageid" id="villageid">
							<option value="0">--请选择小区--</option>
							<?php foreach($villagelist as $vls){ ?>
							<option value="{$vls['villageid']}" {$userinfo['villageid'] == $vls['villageid'] ? 'selected' : ''}>{$vls['title']}</option>
							<?php } ?>
						</select>
					</span>
                </td>
				<td style="background-color: #f9f9f9;text-align: right">房间编号：</td>
                <td style="background-color: white">
					<input type="text" name="doornumber" id="doornumber" class="input-text radius" value="{$userinfo['doornumber']}" />
				</td>
            </tr>
			<tr>	
				<td style="background-color: #f9f9f9;text-align: right">月租：</td>
				<td style="background-color: white">
					<input type="text" name="rent" id="rent" class="input-text radius" value="{$userinfo['rent']}" readonly />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">押金：</td>
				<td style="background-color: white">
					<input type="text" name="deposit" id="deposit" class="input-text radius" value="{$userinfo['deposit']}" readonly />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">物业费：</td>
				<td style="background-color: white">
					<input type="text" name="property" id="property" class="input-text radius" value="{$userinfo['property']}" readonly />
				</td>
			</tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">合同开始时间：</td>
				<td style="background-color: white">
					<span class="select-box radius">
						<input type="text" name="signing_btime" id="signing_btime" class="select layer-date radius times" value="<?php echo $userinfo['userid'] ? date('Y-m-d', $userinfo['signing_btime']) : '';?>" />
					</span>
				</td>
				<td style="background-color: #f9f9f9;text-align: right">合同终止时间：</td>
				<td style="background-color: white">
					<span class="select-box radius">
						<input type="text" name="signing_etime" id="signing_etime" class="select layer-date radius times" value="<?php echo $userinfo['userid'] ? date('Y-m-d', $userinfo['signing_etime']) : '';?>" />
					</span>
				</td>
				<td style="background-color: #f9f9f9;text-align: right">房租截止时间：</td>
				<td style="background-color: white">
					<input type="text" name="rent_time" id="rent_time" class="input-text radius" value="<?php echo !empty($userinfo['rent_time']) ? date('Y-m-d', $userinfo['rent_time']) : '';?>" />
				</td>
			</tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">物业截至时间：</td>
				<td style="background-color: white">
					<input type="text" name="property_time" id="property_time" class="input-text radius" value="<?php echo !empty($userinfo['property_time']) ? date('Y-m-d', $userinfo['property_time']) : '';?>" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">增配物品：</td>
				<td style="background-color: white">
					<span class="select-box radius" style="width: 150px;">
						<select class="select" size="1" name="zeng" id="zeng">
							<option value="-1">--请选择物品--</option>
							<?php foreach($accesslist as $as){ ?>
							<option value="{$as['access_id']}" price="{$as['price']}" subprice="{$as['subprice']}">{$as['title']}</option>
							<?php } ?>
						</select>
					</span>
					<span class="select-box radius" style="width: 50px;">
						<select class="select" size="1" name="zengcount" id="zengcount">
							<option value="1">1</option>
							<option value="2">2</option>
							<option value="3">3</option>
							<option value="4">4</option>
							<option value="5">5</option>
						</select>
					</span>
				</td>
				<td style="background-color: #f9f9f9;text-align: right">减配物品：</td>
				<td style="background-color: white">
					<span class="select-box radius" style="width: 150px;">
						<select class="select" size="1" name="jian" id="jian">
							<option value="-1">--请选择物品--</option>
							<?php foreach($accesslist as $as){ ?>
							<option value="{$as['access_id']}" price="{$as['price']}" subprice="{$as['subprice']}">{$as['title']}</option>
							<?php } ?>
						</select>
					</span>
					<span class="select-box radius" style="width: 50px;">
						<select class="select" size="1" name="jiancount" id="jiancount">
							<option value="1">1</option>
							<option value="2">2</option>
							<option value="3">3</option>
							<option value="4">4</option>
							<option value="5">5</option>
						</select>
					</span>
				</td>
			</tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">增配选项：</td>
				<td style="background-color: white" colspan="5">
					<div class="zeng xcc"></div>
				</td>
			</tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">减配选项：</td>
				<td style="background-color: white" colspan="5">
					<div class="jian xcc"></div>
				</td>
			</tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">水表起数：</td>
				<td style="background-color: white">
					<input type="text" name="water" id="water" class="input-text radius" value="{$userinfo['water']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">电表起数：</td>
				<td style="background-color: white">
					<input type="text" name="electric" id="electric" class="input-text radius" value="{$userinfo['electric']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">气表起数：</td>
				<td style="background-color: white">
					<input type="text" name="gas" id="gas" class="input-text radius" value="{$userinfo['gas']}" />
				</td>
			</tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">合同状态：</td>
				<td style="background-color: white">
					<span class="select-box radius" style="width: 180px">
					  	<select class="select mstatus" size="1" user_id="{$user['userid']}">
						  	<option value="0" <?php echo $user['visible'] == 0 ? 'selected' : ''; ?>>已退房</option>
						  	<option value="1" <?php echo $user['visible'] == 1 ? 'selected' : ''; ?>>租用中</option>
					  	</select>
					</span>		
				</td>
				<td style="background-color: #f9f9f9;text-align: right;">是否审核：</td>
				<td style="background-color: white">
					<span class="select-box radius" style="width: 180px">
					  	<select class="select mstatus" size="1" user_id="{$user['userid']}">
					  		<option value="0" <?php echo $user['is_review'] == 0 ? 'selected' : ''; ?>>未审核</option>
						  	<option value="1" <?php echo $user['is_review'] == 1 ? 'selected' : ''; ?>>已审核</option>
						  	<option value="2" <?php echo $user['is_review'] == 2 ? 'selected' : ''; ?>>未通过</option>
					  	</select>
					</span>	
				</td>
				<td style="background-color: #f9f9f9;text-align: right;">签约时间：</td>
				<td style="background-color: white">{$userinfo['createtime']|date="Y-m-d H:i", ###}</td>
			</tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right; ">备注：</td>
				<td style="background-color: white" colspan="6">
					<input type="text" name="remark" id="remark" class="input-text radius" value="{$userinfo['remark']}" />
				</td>
			</tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">租房图集：</td>
				<td colspan="3">
					<form action="" method="post" class="form form-horizontal" id="uploadform2" enctype="multipart/form-data">
						<span class="btn-upload"> 
							<a href="javascript:void();" class="btn btn-primary radius uploadBtn">
								<i class="Hui-iconfont"></i> 浏览文件
							</a>
							<input type="file" multiple="" name="file[]" class="input-file" onchange="uploadImages('uploadform2');">
						</span>
					</form>
					<div id="imgshow2" style="display: <?php echo empty($userinfo['images']) ? 'none' : 'block'; ?>;">
						<hr />
						<div id="imgs">
							<?php foreach($userinfo['images'] as $img){ ?>
							<img src="__PUBLIC__/upload/{$img}" style="width: 100px; height: 100px; margin-right:10px;" class="radius" />
							<?php } ?>
						</div>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<input type="hidden" name="images" id="images" value="{$userinfo['images']}" />
	<input type="hidden" name="matching" id="matching" value="{$userinfo['matching']}" />
	<div class="mt-5 mb-5 text-c">
		<button type="button" class="btn btn-success radius submitBtn" id="admin-role-save" name="admin-role-save">
			<i class="icon-ok"></i> 确 定
		</button>
	</div>
	<div class="panel panel-primary">
		<div class="panel-header">优惠活动</div>
		<div id="eventinfo">
			<include file="Member/eventinfo" />
		</div>
	</div>
</div>
<script>
	var imagelist = <?php echo json_encode($userinfo['images']);?> || [];
	function uploadImages(formName){
		var load = layer.load(2);
		$("#"+ formName).ajaxSubmit({
			type:'post',
			url:'../index/upload.html',
			success:function(data){
				layer.close(load);
				var data = JSON.parse(data);
				if(data.errCode/1 > 0){
					layer.msg('上传成功', {icon:1, time: 2000});
					if(formName == 'uploadform'){
						$("#images").val(data.errMsg);
						$("#imgshow").show();
						$("#imgshow img").attr('src', "__PUBLIC__/upload/"+ data.errMsg);
					}else{
						imagelist.push(data.errMsg); //保存图片
						data.errMsg = "__PUBLIC__/upload/" + data.errMsg;
						var img = '<img src="'+ data.errMsg +'" style="width: 100px; height: 100px; margin-right:10px;" class="radius" />';
						$("#imgshow2").show();
						$("#imgshow2 div").append(img);
					}
				}else{
					layer.msg(data.errMsg, {icon:2, time: 2000});
				}
			},
			error:function(XmlHttpRequest,textStatus,errorThrown){
				
			}
		});
	}
	
	function clearOption(child){
		$(child).remove();
	}

	$(document).ready(function(){
		//设置时间控件
		$(".time").on('click', function(){
			laydate({istime: true, format: 'YYYY-MM-DD'});
		});
		
		//根据分店ID获取小区列表
		$("#shop_id").on('change', function(){
			var shopid = $(this).val();
			$.get('../shop/getvillage.html', {shopid: shopid}, function(data){
				$("#villageid").html(data);
			});
		});
		
		/**
		 * 判断享受的活动
		 **/
		$(".times").on('click', function(){
			laydate({
				istime: true, 
				format: 'YYYY-MM-DD',
				choose: function(dates){
					var btime = $("#btime").val(),
						etime = $("#etime").val();
					if(btime.length && etime.length){
						$.get('ajaxevent.html', {btime: btime, etime: etime, roomnumber: $("#room_number").val()}, function(data){
							$("#eventinfo").html(data);
						});
					}else{
						//layer.msg('请选择完合同时间', {icon: 5, time: 2000});
					}
				}
			});
		});
		
		/**
		 * 增减配单价设置
		 **/
		$("#zeng").on('change', function(){
			var obj = $(this);
			var price = obj.find("option:selected").attr('price'),
				subprice = obj.find("option:selected").attr('subprice'),
				title = obj.find("option:selected").text(),
				accessid = obj.val();
			var count = 1;
			var ahtml = '<a href="javascript:void(0);" onclick="clearOption(this);" class="xz" aid="'+ accessid +'" count="'+ count +'">'+ title +'(￥'+ price + ')' + '×<i>' + count +'</i></a>';
			//判断是否存在减配项中
			var isadd = true;
			$("div.jian a").each(function(){
				if($(this).attr('aid')/1 == accessid/1){
					isadd = false;
					return false;
				}
			});

			if(!isadd){
				layer.msg("该物品已存在减配项中", {icon: 5, time: 2000});
				return;
			}
			//判断是否已经选择
			if($("div.zeng a").length <= 0){
				$("div.zeng").append(ahtml);
			}else{
				var flag = true;
				$("div.zeng a").each(function(){
					if($(this).attr('aid')/1 == accessid/1){
						flag = false;
						return false;
					}
				});
				//执行添加
				if(flag){
					$("div.zeng").append(ahtml);
				}
			}
			//切换数据
			$("#zengcount").prop('selectedIndex', 0);
		});
		
		/**
		 * 修改数量
		 **/
		$("#zengcount").on('change', function(){
			//获取物品类型
			var accessid = $("#zeng").val();
			var count = $(this).val();
			$("div.zeng a").each(function(){
				if($(this).attr('aid')/1 == accessid/1){
					//修改数量
					$(this).attr('count', count);
					$(this).find("i").html(count);
				}
			});
		});

		$("#jian").on('change', function(){
			var obj = $(this);
			var price = obj.find("option:selected").attr('price'),
				subprice = obj.find("option:selected").attr('subprice'),
				title = obj.find("option:selected").text(),
				accessid = obj.val();
			var count = 1;
			//判断是否已经选择
			var ahtml = '<a href="javascript:void(0);" onclick="clearOption(this);" class="xz" aid="'+ accessid +'" count="'+ count +'">'+ title +'(￥'+ price + ')' + '×<i>' + count +'</i></a>';
			//判断是否存在增配项中
			var isadd = true;
			$("div.zeng a").each(function(){
				if($(this).attr('aid')/1 == accessid/1){
					isadd = false;
					return false;
				}
			});

			if(!isadd){
				layer.msg("该物品已存在增配项中", {icon: 5, time: 2000});
				return;
			}

			//判断是否已经选择
			if($("div.jian a").length <= 0){
				$("div.jian").append(ahtml);
			}else{
				var flag = true;
				$("div.jian a").each(function(){
					if($(this).attr('aid')/1 == accessid/1){
						flag = false;
						return false;
					}
				});
				//执行添加
				if(flag){
					$("div.jian").append(ahtml);
				}
			}
			//切换数据
			$("#jiancount").prop('selectedIndex', 0);
		});

		/**
		 * 修改数量
		 **/
		$("#jiancount").on('change', function(){
			//获取物品类型
			var accessid = $("#jian").val();
			var count = $(this).val();
			$("div.jian a").each(function(){
				if($(this).attr('aid')/1 == accessid/1){
					//修改数量
					$(this).attr('count', count);
					$(this).find("i").html(count);
				}
			});
		});

		/**
		 * 提交数据
		 **/
		$(".submitBtn").on('click', function(){
			var phone = $("#phone").val() || "";
			if(phone.length <= 0 || phone.length != 11){
				layer.msg('请正确输入联系方式', {icon: 5, time: 2000});
				return false;
			}
			var nickname = $("#nickname").val();
			if(nickname.length > 20){
				layer.msg('姓名长度在1～20个字符之间', {icon: 5, time: 2000});
				return false;
			}
			var card = $("#card").val();
			if(card.length <= 0){
				layer.msg('请输入身份证号', {icon: 5, time: 2000});
				return false;
			}
			var contract = $("#contract").val();
			if(contract.length <= 0){
				layer.msg('请输入合同编号', {icon: 5, time: 2000});
				return false;
			}
			var shop_id = $("#shop_id").val();
			if(shop_id/1 <= 0){
				layer.msg('请选择分店', {icon: 5, time: 2000});
				return false;
			}
			var villageid = $("#villageid").val();
			if(villageid/1 <= 0){
				layer.msg('请选择小区', {icon: 5, time: 2000});
				return false;
			}
			var doornumber = $("#doornumber").val();
			if(doornumber.length <= 0){
				layer.msg('请选择小区', {icon: 5, time: 2000});
				return false;
			}
			if($("#btime").val() == ""){
				layer.msg("请选择合同开始时间", {icon: 2, time:2000});
				return false;
			}
			if($("#etime").val() == ""){
				layer.msg("请选择合同截止时间", {icon: 2, time:2000});
				return false;
			}
			var matching = "";
			//获取复选框值
			$("div.check-box input").each(function(){
				if($(this).is(":checked")){
					matching += $(this).val() + ',';
				}
			});
			$("#matching").val(matching);
			var load = layer.load(2);
			$.post('contractinfo.html', $("#form-user-character-add").serialize(), function(row){
				layer.close(load);
				if(row/1 == 1){
					layer.msg("编辑成功", {icon: 1, time: 2000}, function(){
						window.parent.location.reload(); //刷新
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    	parent.layer.close(index);
					});
				}else{
					layer.msg("编辑失败", {icon: 2, time: 2000});
				}
			});
		});
	});
</script>
</body>
</html>